home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Filling Shapes with a Gradient Brush / Creating a Linear Gradient / Horizontal Linear Gradients / GDITEST63.dpr
Encoding:
Text File  |  2003-10-15  |  2.5 KB  |  101 lines

  1. program GDITEST63;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   pen: TGPPen;
  14.   linGrBrush: TGPLinearGradientBrush;
  15. begin
  16.   graphics := TGPGraphics.Create(DC);
  17.  
  18.  linGrBrush := TGPLinearGradientBrush.Create(
  19.    MakePoint(0, 10),
  20.    MakePoint(200, 10),
  21.    MakeColor(255, 255, 0, 0),   // opaque red
  22.    MakeColor(255, 0, 0, 255));  // opaque blue
  23.  
  24.   pen:= TGPPen.Create(linGrBrush);
  25.  
  26.   graphics.DrawLine(pen, 0, 10, 200, 10);
  27.   graphics.FillEllipse(linGrBrush, 0, 30, 200, 100);
  28.   graphics.FillRectangle(linGrBrush, 0, 155, 500, 30);
  29.  
  30.   linGrBrush.Free;
  31.   pen.Free;
  32.   graphics.Free;
  33. end;
  34.  
  35.  
  36. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  37. var
  38.   Handle: HDC;
  39.   ps: PAINTSTRUCT;
  40. begin
  41.   case message of
  42.     WM_PAINT:
  43.       begin
  44.         Handle := BeginPaint(Wnd, ps);
  45.         OnPaint(Handle);
  46.         EndPaint(Wnd, ps);
  47.         result := 0;
  48.       end;
  49.  
  50.     WM_DESTROY:
  51.       begin
  52.         PostQuitMessage(0);
  53.         result := 0;
  54.       end;
  55.  
  56.    else
  57.       result := DefWindowProc(Wnd, message, wParam, lParam);
  58.    end;
  59. end;
  60.  
  61. var
  62.   hWnd     : THandle;
  63.   Msg      : TMsg;
  64.   wndClass : TWndClass;
  65. begin
  66.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  67.    wndClass.lpfnWndProc    := @WndProc;
  68.    wndClass.cbClsExtra     := 0;
  69.    wndClass.cbWndExtra     := 0;
  70.    wndClass.hInstance      := hInstance;
  71.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  72.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  73.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  74.    wndClass.lpszMenuName   := nil;
  75.    wndClass.lpszClassName  := 'GettingStarted';
  76.  
  77.    RegisterClass(wndClass);
  78.  
  79.    hWnd := CreateWindow(
  80.       'GettingStarted',       // window class name
  81.       'Horizontal Linear Gradients',       // window caption
  82.       WS_OVERLAPPEDWINDOW,    // window style
  83.       Integer(CW_USEDEFAULT), // initial x position
  84.       Integer(CW_USEDEFAULT), // initial y position
  85.       Integer(CW_USEDEFAULT), // initial x size
  86.       Integer(CW_USEDEFAULT), // initial y size
  87.       0,                      // parent window handle
  88.       0,                      // window menu handle
  89.       hInstance,              // program instance handle
  90.       nil);                   // creation parameters
  91.  
  92.    ShowWindow(hWnd, SW_SHOW);
  93.    UpdateWindow(hWnd);
  94.  
  95.    while(GetMessage(msg, 0, 0, 0)) do
  96.    begin
  97.       TranslateMessage(msg);
  98.       DispatchMessage(msg);
  99.    end;
  100. end.
  101.